-
Notifications
You must be signed in to change notification settings - Fork 409
feat(dc): Add executeQuery and executeMutation APIs to Data Connect #2979
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Note:The integration tests have a huge diff because I moved the existing tests under a new parent |
Forgot a few changes! Didn't know that you could close and re-open :P thanks Yuchen! |
wait - need to privatize the execute API, execution should come from operation refs (in a future PR) |
user_upsert(data: { id: "fred_id", address: "32 Elm St.", name: "Fred" }) | ||
} | ||
mutation updateFredrickUserImpersonation @auth(level: USER) { | ||
mutation updateFredrickUserImpersonation @auth(level: USER, insecureReason: "test") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: These changes likely require a re-deploy on the CI project
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, they deff do - I'll leave this comment open to make sure it gets re-deployed! Tagging @lahirumaramba
test/unit/data-connect/data-connect-api-client-internal.spec.ts
Outdated
Show resolved
Hide resolved
test/unit/data-connect/data-connect-api-client-internal.spec.ts
Outdated
Show resolved
Hide resolved
…s, bypassing auth policies
…ions, bypassing auth policies
…rationRef.execute() API
} | ||
|
||
// @public | ||
export function validateAdminArgs<Variables extends object>(connectorConfig: ConnectorConfig, dcOrVarsOrOptions?: DataConnect | Variables | OperationOptions, varsOrOptions?: Variables | OperationOptions, options?: OperationOptions, hasVars?: boolean, validateVars?: boolean): { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lahirumaramba Any opinions on this? We only need this for the generated SDK, and we don't intend for developers to use this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, is there a way to not export this from the public API surface?
…nts, revert package changes
getDataConnectStub = sinon.stub(DataConnectService.prototype, 'getDataConnect').returns(stubDcInstance); | ||
|
||
// initializing app required, "using" it is required for successful build/compile | ||
app = initializeApp(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might be able to get away with just calling initializeApp
without setting the app to something
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was able to remove the initializeApp
call entirely. Done.
}); | ||
|
||
it('should successfully parse the provided options', () => { | ||
const { dc: dcInstance, vars: inputVars, options: inputOpts } = validateAdminArgs<object>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason why the object
is needed?
connectorConfig, variables, undefined, undefined, true, false | ||
); | ||
expect(dcInstance).to.deep.equal(stubDcInstance); | ||
expect(inputVars).to.deep.equal(inputVars); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo?
expect(inputVars).to.deep.equal(inputVars); | |
expect(inputVars).to.deep.equal(variables); |
// Data Connect | ||
import './data-connect/index.spec'; | ||
import './data-connect/data-connect-api-client-internal.spec'; | ||
// import './data-connect/validate-admin-args.spec'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should uncomment this if we want to run the tests in validate-admin-args.spec.ts
{ | ||
"name": "firebase-admin", | ||
"version": "13.5.0", | ||
"version": "13.4.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can revert this. We update the package.json only during a release PR (which we will handle separately from this PR)
public executeQuery<Data>( | ||
name: string, | ||
options?: OperationOptions | ||
): Promise<ExecuteOperationResponse<Data>>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this handle the method overload correctly? If I call executeQuery('myQuery', { impersonate: ... })
would it take options
as variables
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If that breaks the method overload we need to perform a runtime check to differentiate them.
public executeQuery<Data, Variables>(
name: string,
variablesOrOptions?: Variables | OperationOptions,
options?: OperationOptions
): Promise<ExecuteOperationResponse<Data>> {
public executeQuery<Data>( | ||
name: string, | ||
options?: OperationOptions | ||
): Promise<ExecuteOperationResponse<Data>>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If that breaks the method overload we need to perform a runtime check to differentiate them.
public executeQuery<Data, Variables>(
name: string,
variablesOrOptions?: Variables | OperationOptions,
options?: OperationOptions
): Promise<ExecuteOperationResponse<Data>> {
DataConnect, | ||
} from './data-connect' | ||
export { | ||
validateAdminArgs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this function is only for internal usage let's not export it to the public API surface here
* Interface representing GraphQL options. | ||
* Interface representing ExecuteOperation response. | ||
*/ | ||
export interface ExecuteOperationResponse<GraphqlResponse> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this interface identical to ExecuteGraphqlResponse
? If that is the case and if we don't see it changing in the future, it might be better to create a type alias.
export type ExecuteOperationResponse<T> = ExecuteGraphqlResponse<T>;
API Changes
executeQuery()
andexecuteMutation()
tosrc/data-connect/data-connect.ts
. These allow users to call deployed operations with impersonated auth credentials.Testing
executeGraphql*
APIsexecuteGraphql*
APIs